<?php

error_reporting(0);

require_once("includes/pagetop.php");
include_once("updates/CommonFeatures.php");
include_once("includes/common_snippets.php");
include_once("lib/GenericCRUDOperations.php");
include_once("smiley.php");

class ReadFeedAction extends PostAction{
    
    //public $postAction;
    private $loggedInUserId=0;
    public $pdodbobj;
    public $connstatus=false;
    public $eLog;
    function __construct() {
          $this->eLog= new Log();
          
       try{
            
            $this->pdodbobj= new DB();
            $this->connstatus=$this->pdodbobj->connect();
            
            if(isset($_SESSION['Allyfolio_User_ID'])&& !empty($_SESSION['Allyfolio_User_ID']) && is_numeric($_SESSION['Allyfolio_User_ID'])){
                $this->loggedInUserId=trim($_SESSION['Allyfolio_User_ID']);    
            }
            else{
                $this->eLog->writeVerbose('ReadFeedAction:__construct():: Invalid Session => '.$_SESSION['Allyfolio_User_ID'].' \t');
                die('ReadFeedAction:__construct():: Invalid Session => '.$_SESSION['Allyfolio_User_ID'].' \t'. "\n");
            }
        }
        catch(Exception $ex){
            $this->eLog->writeException('ReadFeedAction:__construct():: \t'. $ex->getMessage(). "\n");
            die('ReadFeedAction:__construct():: \t'. $ex->getMessage(). "\n");   
        }
   }
        
    //check if user is authorised by comparining passed userid with session id
    public function isAuthenticated($userId){
        //global $loggedInUserId;
        if(isset($userId) && !empty($userId)  && is_numeric($userId) && $this->loggedInUserId==$userId){
            $this->eLog->writeVerbose('User: '.$userId.' is auhenticated \t');
            return true;
        }
        else{
            $this->eLog->writeVerbose('User: '.$userId.' is Not authenticated \t');
            return false;
        }
    }
    
    
        
    public function ReadPostComments($postId){
        $postAction= new PostAction();
        $actionRes = $postAction->Failure;
        $postStatusTypes= new PostStatus();
        try{
            $this->eLog->writeVerbose('ReadFeedAction:ReadPostComments():: Starts \t');
            //do your stuff
            if($this->loggedInUserId!=null && is_numeric($this->loggedInUserId) && $this->loggedInUserId>0){                
                if($this->pdodbobj!=null){
                    $selquery="SELECT upc . * ,u.Full_Name,u.Last_Name,u.Gender,u.Profile_Pic_Path,u.Login_Status,u.Is_Celebrity,u.Profile_Status
                                FROM af_user_posts_comments AS upc, af_users AS u
                                WHERE upc.Post_ID =:postid
                                AND upc.Status =:statusid
                                AND upc.User_ID = u.User_ID";
//                    $selquery="select * from af_user_posts_comments where Post_ID=:postid and Status=:statusid";
                    $feedCommentsRecords= $this->pdodbobj->fetch_array(
                                        $this->pdodbobj->query($selquery,
                                                                 array(
                                                                 ":postid"=>$postId,
                                                                 ":statusid"=>$postStatusTypes->Visible
                                                                 )
                                                               ));
                //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        
                    return $feedCommentsRecords;
                }
                else{
                    $actionRes=$postAction->Failure;
                    $actionRes["msg"]="Unable to connect to db";
                    $this->eLog->writeVerbose('ReadFeedAction:ReadPostComments():: Message => '.$actionRes["msg"].' \t');
                }
            }
            else{
                $actionRes=$postAction->Failed_For_Invalid_Session;
                $this->eLog->writeVerbose('ReadFeedAction:ReadPostComments():: Message => '.$actionRes["msg"].' \t');
                //die('PerformPostAction:PostData():: Invalid UserId \t'."\n");
            }
            $this->eLog->writeVerbose('ReadFeedAction:ReadPostComments():: Ends \t');
        }
        catch(Exception $ex){
            $actionRes['msg']=$ex->getMessage();
            $this->eLog->writeException('ReadFeedAction:ReadPostComments():: Exception => '.$ex->getMessage().' \t');
            die('ReadNewsFeed:ReadPostComments():: \t'. $ex->getMessage(). "\n");   
        }
        return $actionRes;
    }
    
    public function ReadPostUploads($postId){
        $postAction= new PostAction();
        $actionRes = $postAction->Failure;
        $postStatusTypes= new PostStatus();
        try{
            $this->eLog->writeVerbose('ReadFeedAction:ReadPostUploads():: Starts \t');
            //do your stuff
            if($this->loggedInUserId!=null && is_numeric($this->loggedInUserId) && $this->loggedInUserId>0){                
                if($this->pdodbobj!=null){
                    $selquery="select * from af_user_posts_media_uploads where Post_ID=:postid and Status=:statusid";
                    $feedCommentsRecords= $this->pdodbobj->fetch_array(
                                        $this->pdodbobj->query($selquery,
                                                                 array(
                                                                 ":postid"=>$postId,
                                                                 ":statusid"=>$postStatusTypes->Visible
                                                                 )
                                                               ));
                //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        
                    return $feedCommentsRecords;
                }
                else{
                    $actionRes=$postAction->Failure;
                    $actionRes["msg"]="Unable to connect to db";
                    $this->eLog->writeVerbose('ReadFeedAction:ReadPostUploads():: Message => '.$actionRes["msg"].' \t');
                }
            }
            else{
                $actionRes=$postAction->Failed_For_Invalid_Session;
                $this->eLog->writeVerbose('ReadFeedAction:ReadPostUploads():: Message => '.$actionRes["msg"].' \t');
                //die('PerformPostAction:PostData():: Invalid UserId \t'."\n");
            }
            $this->eLog->writeVerbose('ReadFeedAction:ReadPostUploads():: Ends \t');
        }
        catch(Exception $ex){
            $actionRes['msg']=$ex->getMessage();
            $this->eLog->writeException('ReadFeedAction:ReadPostUploads():: Exception => '.$actionRes["msg"].' \t');
            die('ReadNewsFeed:ReadPostUploads():: \t'. $ex->getMessage(). "\n");   
        }
        return $actionRes;
    }                    
    
    /**
     PostData : used to post any data with privacy setting, userid, and enumerated post type
     
     Result: PostAction::Contants (default: PostAction::Failure ==> 200)
     * 
     */
    public function ReadStatusUpdates($userId,$privacyType=PrivacySettings::DefaultSetting,$lastfeedid=0,$limitlen=10,$whichPostsToRead,$parentid=0,$clusteredId=0){
        //echo ("Parameters: postcontent:".$postcontent."\t Userid:".$userId."\t postType:".$postType."\t privacyType: ".$privacyType);
        $postAction= new PostAction();
        $actionRes = $postAction->Failure;
        try{
            $this->eLog->writeVerbose('ReadFeedAction:ReadStatusUpdates():: Starts \t');
            //echo "<br>-->  doing stuff-->";
            //do your stuff
            if(ReadFeedAction::isAuthenticated($userId)){
                
                if($this->pdodbobj!=null){// check if connection object is set to connection
                    //read own posts 
                    //read posts from friends based on privacy setting: public or friends  
                    //read posts from from cluster or groups
                    //,count(upc.User_Comment_ID)as CommentsCount,count(upc.Media_Upload_ID)as MediaCount,
                    /*
    
                        Left Join
                        (
                            af_user_posts_comments as upc
                            on
                            upa.POST_ID=upc.POST_ID
                        )
                        
                        Left Join
                        (
                            af_user_posts_media_uploads as upmu
                            on
                            upa.POST_ID=upmu.POST_ID
                        )
                    */
                    $selquery=" 
                            select *
                                from 
                                    af_user_posts_activities as upa
                                    where 
                                        upa.POST_ID in (
                                            select POST_ID 
                                                from 
                                                    af_user_posts_activities 
                                                where 
                                                    User_ID=:userid 
                                                    
                                            Union
                                            (
                                                /* read posts from friends based on privacy setting: public or friends  */
                                                select POST_ID 
                                                    from 
                                                        af_user_posts_activities as uPosts
                                                    where 
                                                        uPosts.User_ID in(    
                                                            select User_Friend_ID 
                                                                from 
                                                                    af_user_friends as uFriends,
                                                                    af_user_privacy_settings as fPrivacySettings
                                                                where
                                                                    uFriends.User_ID=:userid
                                                                    and
                                                                    fPrivacySettings.User_ID=uFriends.User_Friend_ID
                                                        )
                                                        and uPosts.Privacy_Type_ID in(:publicSetting,:friendsSetting)
                                            )
                                        )
                                                                                                                                                                                                       
                                        
                              ";
                              
                              if(trim($whichPostsToRead)==7 /* techno */ || trim($whichPostsToRead)==6 /* blog */){
                                $selquery.=" and Post_Type_ID=".$whichPostsToRead;
                              }
                              
                              //." and Parent_ID=".$parentid
                              if($parentid!="" && is_numeric($parentid) && $parentid>0){
                                $selquery.=" and Parent_ID=".$parentid;
                              }
                              if($lastfeedid>0){
                                $selquery.=" and Post_ID<=:last_post_id
                                        order by Last_Modified_Date desc";
                              }
                              else{
                                $selquery.="
                                        order by Last_Modified_Date desc";
                              }
                              $selquery.=" limit ".$limitlen." ";
                              
                              //echo $selquery;
//                              echo "\n userid: ".$userId;
//                              echo "\n public setting: ".PrivacySettings::PublicSetting;
//                              echo "\n friendssettings: ".PrivacySettings::FriendsSetting;
//                              echo "\n last_post_id".$lastfeedid;
                              
                    $feedRecords= $this->pdodbobj->fetch_array(
                                                    $this->pdodbobj->query($selquery,
                                                                 array(
                                                                 ":userid"=>$userId,
                                                                 ":publicSetting"=>PrivacySettings::PublicSetting,
                                                                 ":friendsSetting"=>PrivacySettings::FriendsSetting,
                                                                 ":last_post_id"=>$lastfeedid
                                                                 )));
                    
                    
                    return $feedRecords;
                }
                else{
                    $actionRes=$postAction->Failure;
                    $actionRes["msg"]="Unable to connect to db";
                    $this->eLog->writeVerbose('ReadFeedAction:ReadStatusUpdates():: Message => '.$actionRes["msg"].' \t');
                }
//                $actionRes=$postAction->Success;
            }
            else{
                $actionRes=$postAction->Failed_For_Invalid_Session;
                $this->eLog->writeVerbose('ReadFeedAction:ReadStatusUpdates():: Message => '.$actionRes["msg"].' \t');
                //die('PerformPostAction:PostData():: Invalid UserId \t'."\n");
            }
            $this->eLog->writeVerbose('ReadFeedAction:ReadStatusUpdates():: Ends \t');
        }
        catch(Exception $ex){
            $actionRes['msg']=$ex->getMessage();
            $this->eLog->writeException('ReadFeedAction:ReadStatusUpdates():: Exception => '.$actionRes["msg"].' \t');
            die('ReadNewsFeed:ReadStatusUpdates():: \t'. $ex->getMessage(). "\n");   
        }
        return $actionRes;
    }
    
    public function getPostLikesCount($postId){
        //echo ("Parameters: postcontent:".$postcontent."\t Userid:".$userId."\t postType:".$postType."\t privacyType: ".$privacyType);
        $oNotification=new Notifications();
        $totalRowsCount=$oNotification->getFeedLikeCommentShareCount($postId,"like");
        /*
        $postAction= new PostAction();
        $totalRowsCount=0;
        try{
            if($this->pdodbobj!=null){// check if connection object is set to connection
                $selquery=" select * from af_user_post_likes where POST_ID=:postid";                              
                $totalRowsCount=$this->pdodbobj->fetch_num_of_rows($this->pdodbobj->query($selquery,array(":postid"=>$postId)));
            }
        }
        catch(Exception $ex){
            $this->eLog->writeException('ReadFeedAction:getPostLikesCount():: Exception => '.$actionRes["msg"].' \t');
        }*/
        return $totalRowsCount;
    }
    public function getCommentLikesCount($feedid,$commentId){
        $oNotification=new Notifications();
        $totalRowsCount=$oNotification->getFeedLikeCommentShareCount($feedid,"commentlike",$commentId);
        return $totalRowsCount;
    }
    public function getPostShareCount($postId){
        //echo ("Parameters: postcontent:".$postcontent."\t Userid:".$userId."\t postType:".$postType."\t privacyType: ".$privacyType);
        $oNotification=new Notifications();
        $totalRowsCount=$oNotification->getFeedLikeCommentShareCount($postId,"share");
        return $totalRowsCount;
    }
    public function getPostCommentCount($postId){
        //echo ("Parameters: postcontent:".$postcontent."\t Userid:".$userId."\t postType:".$postType."\t privacyType: ".$privacyType);
        $oNotification=new Notifications();
        $totalRowsCount=$oNotification->getFeedLikeCommentShareCount($postId,"comment");
        return $totalRowsCount;
    }
    public function getPostSnapshotDetails($postId,$whichPostsToRead,$parentid=0,$clusteredId=0){
        //echo ("Parameters: postcontent:".$postcontent."\t Userid:".$userId."\t postType:".$postType."\t privacyType: ".$privacyType);
        $postAction= new PostAction();
        $actionRes = $postAction->Failure;
        try{
            $this->eLog->writeVerbose('ReadFeedAction:getPostSnapshotDetails():: Starts \t');
            //echo "<br>-->  doing stuff-->";
            //do your stuff
            if(ReadFeedAction::isAuthenticated($this->loggedInUserId)){
                
                if($this->pdodbobj!=null){// check if connection object is set to connection
                    $selquery=" select 
                                    upa.*,u.Full_Name,u.Last_Name,u.Gender,u.Profile_Pic_Path,u.Login_Status,u.Is_Celebrity,u.Profile_Status
                                from 
                                    af_user_posts_activities as upa,
                                    af_users as u
                                where 
                                    upa.POST_ID=:postid
                                    and 
                                    upa.User_ID=u.User_ID
                                    ";
                              
                              if(trim($whichPostsToRead)==7 /* techno */ || trim($whichPostsToRead)==6 /* blog */){
                                $selquery.=" and Post_Type_ID=".$whichPostsToRead;
                              }
                              
                              //." and Parent_ID=".$parentid
                              if($parentid!="" && is_numeric($parentid) && $parentid>0){
                                $selquery.=" and Parent_ID=".$parentid;
                              }
                    $feedRecords= $this->pdodbobj->fetch_array($this->pdodbobj->query($selquery,array(":postid"=>$postId)));
                    
                    
                    return $feedRecords;
                }
                else{
                    $actionRes=$postAction->Failure;
                    $actionRes["msg"]="Unable to connect to db";
                    $this->eLog->writeVerbose('ReadFeedAction:getPostSnapshotDetails():: Message => '.$actionRes["msg"].' \t');
                }
//                $actionRes=$postAction->Success;
            }
            else{
                $actionRes=$postAction->Failed_For_Invalid_Session;
                $this->eLog->writeVerbose('ReadFeedAction:getPostSnapshotDetails():: Message => '.$actionRes["msg"].' \t');
                //die('PerformPostAction:PostData():: Invalid UserId \t'."\n");
            }
            $this->eLog->writeVerbose('ReadFeedAction:getPostSnapshotDetails():: Ends \t');
        }
        catch(Exception $ex){
            $actionRes['msg']=$ex->getMessage();
            $this->eLog->writeException('ReadFeedAction:getPostSnapshotDetails():: Exception => '.$actionRes["msg"].' \t');
            die('ReadNewsFeed:getPostSnapshotDetails():: \t'. $ex->getMessage(). "\n");   
        }
        return $actionRes;
    }
}


//print_r($_SESSION);
//die();




$patharr=explode("/",$_SERVER["REQUEST_URI"]);
$lastvars=end($patharr);
$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);

//echo $_SERVER["SERVER_NAME"]." = ".$_SERVER["DOCUMENT_ROOT"]." = ".$_SERVER["REQUEST_URI"]."<br>".$afterWampToProjectRootPath;

$logObj=new Log();
$noofappsloadpermoreclick=1;
$noofsponcersdefault=5;


//CommonFeatures.php > Userdetails object
try{

    $loggedUserObj=new UserDetails();
    if (!isset($_SESSION["User_details"])){
        $_SESSION["User_details"]=$loggedUserObj->getUserDetails($_SESSION["Allyfolio_User_ID"],true);
    }
    //$pset=$loggedUserObj->getUserPrivacyDetails($loggedUserObj->userId);
    $loggedUserObj=$_SESSION["User_details"];
    //$loggedUserObj->latestFriendNotificationsArr=array(1=>"sumer",2=>"vikas");
/*echo "<pre>";
print_r($loggedUserObj);
echo "</pre>";
*/
    
}
catch(Exception $ex){
    $logObj->writeException("home.php Exception: => ".$ex->getMessage());
    die("Home.php fetching user details".$ex->getMessage());
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | Home </title>



<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>
<script src="js/functions.js"></script>
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>

<!-- add location 
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script src="js/locationpicker.jquery.js"></script>
-->
<!-- add location 
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

-->


<script type="text/javascript">

function getLatLongForAddress(address,lociD){
    //alert(address);
    /*
    var mylatlong={'lat':0.00,'lng':0.00};
    var geocoder = new google.maps.Geocoder();    
    geocoder.geocode({ 'address': address}, 
        function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
            mylatlong.lat=latitude;
            mylatlong.lng=longitude;
          } 
        }
    ); 
    pointmyaddress(lociD,mylatlong);
    */
    codeAddress(address,lociD); 
}
/*
function pointmyaddress(locID,locationpoints){
    alert("locationid: "+locID+" points: lat-"+locationpoints.lat+" long - "+locationpoints.lng)
    $('#'+locID).locationpicker({
    location: {latitude: locationpoints.lat, longitude: locationpoints.lng},	
    radius: 200
});
}*/
</script>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>

function initialize() {
  
}

function codeAddress(address,locpath) {
    try{
        var geocoder;
        var map;
        geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-26.4503329, 74.6399125000000);
      var mapOptions = {
        zoom: 8,
        center: latlng
      }  
      map = new google.maps.Map(document.getElementById(locpath), mapOptions);
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //alert("locationid: "+locpath+" points: lat-"+results[0].geometry.location.lat()+" long - "+results[0].geometry.location.lng())
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map,
              position: results[0].geometry.location
          });
        } else {
          alert('Geocode was not successful for the following reason: ' + status);
        }
      });
  }
  catch(e){
    
  }
}

//google.maps.event.addDomListener(window, 'load', initialize);

</script>
    
	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<?php include_once "includes/main_header.php"; ?>

    <!--=================Header end=======================-->

    

    

    <script type="text/javascript">

    $(function() { $('input, textarea').placeholder();});

</script>

<style type="text/css">

    .chat_box{

        display:none;

    }

    .placeholder {

      color: #cccccc;

      }
/* emotions */
#emotionsdrp{
    position: absolute;
    padding: 4px;
}

#emotionsdrp div .em{
    cursor: pointer;
    padding: 2px;
} 
#emotionsdrp{
    background-color: gainsboro;
    width: 130px;
}
.em{
    
}
.em:hover{
    background-color: cadetblue;
    cursor:pointer;
}
</style>



<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	

	}

	.new tr td{ vertical-align:top}

	

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

    

    /* added by sujeet */

    .privacy-drp-menu{

        border:1px solid blue;

        display: none;

    }

    .privacy-drp-menu-items{

        border-bottom: 1px solid gray;

        cursor:pointer;

    }

    .comment{

        width: 84%;

        height: 25px;

        padding-left: 4px;

        padding-right: 4px;

        border:none; 

        background:none;

    }   

    .listenMe{

        width: 100%;

        text-align: center;

        padding-top: 14px;

        padding-bottom: 14px;

    }

    .feed{

        margin-top: 20px;

    }
    .para{
        line-height: 1.75 !important;
    }
    .countUpdates {
        /* background: #000; */
        padding: 1px;
        color: #000;
        /* border-radius: 5px; */
        padding: 0 5px;
    }
    .linktxt{
        color:blue;
    }
    .linktxt:hover{
        color:blue;
        text-decoration: underline;
    }
    
    /* notification popup */
                    #nav{list-style:none;margin: 0px;padding: 0px;}
                    #nav li {
                    float: left;
                    margin-right: 20px;
                    font-size: 14px;
                    font-weight:bold;
                    }
                    #nav li a{color:#333333;text-decoration:none}
                    #nav li a:hover{color:#006699;text-decoration:none}
    /*notification div */
    #notification_li
{
position:relative
}
#notificationContainer 
{
background-color: #fff;
border: 1px solid rgba(100, 100, 100, .4);
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
position: absolute;
top: 30px;
margin-left: -170px;
width: 400px;
z-index: 10;
display: none; // Enable this after jquery implementation 
}
// Popup Arrow
#notificationContainer:before {
content: '';
display: block;
position: absolute;
width: 0;
height: 0;
color: transparent;
border: 10px solid black;
border-color: transparent transparent white;
margin-top: -20px;
margin-left: 188px;
}
#notificationTitle
{
font-weight: bold;
padding: 8px;
font-size: 13px;
background-color: #ffffff;
/*position: fixed;*/
z-index: 1000;
width: 384px;
border-bottom: 1px solid #dddddd;
}
#notificationsBody
{
/*padding: 33px 0px 0px 0px !important;*/
height:300px;
overflow-x: auto;
}
#notificationFooter
{
background-color: #e9eaed;
text-align: center;
font-weight: bold;
padding: 8px;
font-size: 12px;
border-top: 1px solid #dddddd;
}

/* notification count*/
#notification_count 
{
padding: 3px 7px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: -10px;
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
position: absolute;
margin-top: -11px;
font-size: 11px;
}

.notify{
    padding:10px;
}
</style>

<link href="css/emoticons.css" rel="stylesheet" type="text/css"/>

<!-- custom post submission jquery by sujeet -->
<?php include_once("smiley.php");?>
<script type="text/javascript" src="js/smiley.js"></script>
<script src="js/autoloading.js"></script>
<script src="js/custom_popupshow.js"></script>
<script src="js/jquery.asyncpost.js"></script>
<script type="text/javascript" src="js/jwplayer.js"></script>
</head>



<body style="background-color: #E8F6F6;">

<?php


include_once("updates/ReadNotifications.php");
?>

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <div class="contain-wrap2" style="margin-top:30px; width:100%; ">         

        <div class="home_left">
            <div style="display: none;">
            <?php include_once("home_leftsidebar.php"); ?>
            </div>
		</div>

		<div class="home_right" style="border-left: none !important;">  

        <style>

        #tweets { border-left:1px solid gray; padding-left:20px}

        #overlay { position: absolute; left: 168px; top: 87px;

           width: 408px; height:386px; background: url("../images/transpBlue_overlay.png"); }

        #overlay img { position:relative; left:200px; top:189px; }   

        </style>

        
              
        
                    
                
        <!-- js scrolling -->

        <div id="tweets">

           <!-- Tweets will get loaded from jQuery -->
           <?php
           $uid=$_REQUEST["visitorid"];
           $_SESSION['Allyfolio_User_ID']=$uid;
           $postid=$_REQUEST["post_id"];
           echo "postid: ".$postid;
           $selquery=" select * from af_user_posts_activities as upa where upa.POST_ID=:postid order by Last_Modified_Date desc";                              
           $feedRecords=$pdodbobj->fetch_array($pdodbobj->query($selquery,array(":postid"=>$postid)));
           //print_r($feedRecords);
           
           
           
           function getTaggedUserDetails($taggedUsersList){
                $usersJson="";
                $friendReqJSON[]= new DetailJson();
                $oNotification= new Notifications();
                $UserDetail=array();
                $friendsCount=0;
                for($uCount=0;$uCount<count($taggedUsersList);$uCount++){
                    $UserDetail=$oNotification->getUserDetails($taggedUsersList[$uCount]);
                    $friendReqJSON[$friendsCount]->actionByUserId=$UserDetail["uid"];
                    $friendReqJSON[$friendsCount]->actionByUserName=$UserDetail["uname"];
                    $friendReqJSON[$friendsCount]->actionByUserProfilePicpath=$UserDetail["picpath"];
                    $friendReqJSON[$friendsCount]->actionByUserLink=$UserDetail["plink"];
                    $friendReqJSON[$friendsCount]->actionByUserIsCelibrity=$UserDetail["Is_Celebrity"];
                    $friendsCount++;
                }
                $usersJson= $oNotification->getUserDetailsJSON($friendReqJSON);
                return $usersJson;
            }
            function getNewsFeedcopy($feedID,$newsFeeds,$uid){
                global $relpath;
                //echo "<pre>";
            //        print_r($newsFeeds);
            //    echo "</pre>";
                
                $loggedUserObjlocal=new UserDetails();
                $loggedUserObjlocal->getUserDetails($uid,true);
                $postUserDetail=new UserDetails();
                $commentUserDetail= new UserDetails();
                $postUserDetail->getUserDetails($newsFeeds["User_ID"]);
                
                //echo "<pre>";
//                print_r($loggedUserObjlocal);
//                echo "</pre>";
//                
                $likesharepost="";
                $postFeeds= new ReadFeedAction();
                
                $postComments= array();
                $postUploads=array();
                $taggedUsersList=array();
                $taggingMsgWithPost="";
                
                
                
                if($newsFeeds["Post_ID"]!=null && is_numeric(trim($newsFeeds["Post_ID"])) && trim($newsFeeds["Post_ID"])>0){
                    
                    $postComments=$postFeeds->ReadPostComments($newsFeeds["Post_ID"]);   
                    $postUploads= $postFeeds->ReadPostUploads($newsFeeds["Post_ID"]);
                    //echo "<pre>";
                    //print_r($postUploads);
                    //echo "</pre>";
                    //$postUploads=(isset($postUploads[0]))?$postUploads[0]:array();
                    //reported abused
                    $oDropfilters= new CGetFilters();
                    
                    $postReportAbused=array();
                    $postReportAbused=$oDropfilters->getPostReportAbuseTypes($uid,$newsFeeds["Post_ID"]);
                    
                    if(is_array($postReportAbused) && count($postReportAbused)>0){
                        $postReportAbused=$postReportAbused[0];
                    }
                    //print_r($postReportAbused);    
                    $isReportedAbusedOrHidden=false;
                    if(is_array($postReportAbused) && isset($postReportAbused["Report_Abuse_IDs"]) && isset($postReportAbused["Status"]) && isset($postReportAbused["Is_Approved_By_Admin"]) ){
                        //if report abused and is approved by admin then treat it as approved reported abused
                        if($postReportAbused["Is_Approved_By_Admin"]==1 && (strstr($postReportAbused["Report_Abuse_IDs"],",") || is_numeric($postReportAbused["Report_Abuse_IDs"]))){
                            $isReportedAbusedOrHidden=true;    
                        }
                        //or if not approved as reported abused then check if post is hidden (0)
                        if($postReportAbused["Status"]==0){
                            $isReportedAbusedOrHidden=true;
                        }
                    }
                    if($isReportedAbusedOrHidden)
                        return;
                        
                }
                //echo "da";
                if($newsFeeds["Friend_IDs"]!=""){
                    if(strstr($newsFeeds["Friend_IDs"],",")){
                        $taggedUsersList=explode(",",$newsFeeds["Friend_IDs"]);
                    }
                    else{
                        $taggedUsersList[0]=$newsFeeds["Friend_IDs"];
                    }
                }
                
                $emotionstext="";
                if($newsFeeds["postedemotion"]!="" && strlen($newsFeeds["postedemotion"])>0){
                    $newsFeeds["postedemotion"]=getSmileyDataForSave($newsFeeds["postedemotion"]);
                    $emotionstext="<span class='feel-em'> ".$newsFeeds["postedemotion"]."</span>";
                }
                
                if(is_array($taggedUsersList) && count($taggedUsersList)){
                    $taggingMsgWithPost=' was with {3} <a > {1} {2} </a>';
                    $inputHidden="<input type='hidden' id='ptaguser' name='ptaguser' value='{1}'/>";
                        
                    $taggedUsersJson=getTaggedUserDetails($taggedUsersList);
                    $oNotification= new Notifications();
                    $inputHidden=$oNotification->str_format($inputHidden,$taggedUsersJson);
                    $taggingMsgWithPost=$oNotification->str_format($taggingMsgWithPost,count($taggedUsersList),(count($taggedUsersList)>1)?"peoples":"people",$inputHidden);
                    //$taggingMsgWithPost=str_format($taggingMsgWithPost,count($taggedUsersList),(count($taggedUsersList)>1)?"peoples":"people",$taggedUsersJson);
                }
                //echo "<pre>user postUploads <br>";
            //    print_r($postUploads);
            //    echo "</pre>";
                
                if($postUserDetail->isCelibrity==true){
                   $likesharepost='<!--like/post--> <p ><img src="images/ico/10.png"></p>';
                 }     
                $currentPostId=$newsFeeds["Post_ID"];  
                $postlikes=$postFeeds->getPostLikesCount($currentPostId);
                $postshares=$postFeeds->getPostShareCount($currentPostId);
                $likesharepost.='<p>'.date("d, M Y",$newsFeeds["Last_Modified_Date"]).'</p>
                			<p  >
                                <span style="cursor:pointer">pick</span> 
                                <!--<span style="cursor:pointer"><img src="images/ico/11.png"></span>-->
                                <span id="'.$currentPostId.'_lcount" class="countUpdates">'.$postlikes.'</span>
                            </p>
                			<p >
                                <a style="cursor:pointer">
                                    Share 
                                    <!--<span><img src="images/ico/12.png" style="top:6px;"></span>-->
                                </a>
                                <span id="'.$currentPostId.'_scount" class="countUpdates">'.$postshares.'</span>
                            </p>
                			<p > 
                                <a  style="cursor:pointer">
                                    Privacy
                                </a>
                            </p>
                            <p >
                                <a  class="button" style="cursor:pointer">
                                    Edit Settings
                                </a>
                            </p>';      
                         
                            //echo "<pre>";
            //                print_r($postComments);
            //                echo "</pre>";
                            
                $postlocation="";
                if(strlen(trim($newsFeeds["post_location"]))>0){
                    $newsFeeds["post_location"]=getSmileyDataForSave($newsFeeds["post_location"]);
                    $postlocation="<div> - <span class='post-location'>".trim($newsFeeds["post_location"])."</span></div>";
                    
                    $mappath='<div id="mymap-'.$currentPostId.'" style="width: 480px; height: 200px;"></div>
                                    <script type="text/javascript">
                                        getLatLongForAddress("'.trim($newsFeeds["post_location"]).'","mymap-'.$currentPostId.'");  
                                    </script>
                                    ';
                }
                else{
                    $mappath="";
                }
                $newsFeeds["PostedContent"]=getSmileyDataForSave($newsFeeds["PostedContent"]);
                $feedSection= '<div id="feed'.$currentPostId.'" class="feed">
                <table width="100%" border="0">
                	<tbody>
                        <tr>
                                <td width="14%" valign="top"><div class="other_box" style="float:right"><img src="'.$postUserDetail->profilePicPath.'" width=50 style="padding:4px"/></div></td>
                                <td width="71%" valign="top">
                                    <p class="box_home_heading">'.$postUserDetail->profileName.$taggingMsgWithPost.$emotionstext.$postlocation.'</p>
                                    <p class="box_txt">
                                        '.$newsFeeds["PostedContent"].'
                                    </p>';
                                    
                                    $feedSection.="<br/>".$mappath."<br/>";
                                    if(is_array($postUploads) && count($postUploads)>0){
                                        $videocount=0;
                                        foreach($postUploads as $postUpload){
                                            $feedSection.='<div class="total">';
                                            if($postUpload["Media_Type"]=="IMAGE")
                                            {
                                                $fpathencoded=urlencode($postUpload["Media_Path"]);
                                                $feedSection.='<a href="'.$postUpload["Media_Path"].'" data-lightbox="roadtrip'.$currentPostId.'">
                                                                <img src="'.$postUpload["Media_Path"].'" width="500px">
                                                                <div><a style="float:right;margin-right:25px" href="downloadpics.php?filepathdownload='.$fpathencoded.'">Download !!</a></div>
                                                                </a>';
                                            }
                                            else
                                            {
                                                $feedSection.='
                                                <div id="videouploaded_'.$newsFeeds["Post_ID"].'_'.$videocount.'" style="width:500px;height:350px;"></div>
                                                    <script type="text/javascript">
                                                        jwplayer("videouploaded_'.$newsFeeds["Post_ID"].'_'.$videocount.'").setup({
                                                            "flashplayer": "js/jwplayer.flash.swf",
                                                            "file": "'.$postUpload["Media_Path"].'",
                                                            "image": "images/dummy_video.jpg",
                                                            "controlbar": "bottom",
                                                            "width": "500",
                                                            "height": "350"
                                                        });
                                                    </script>
                                                </div>    
                                                ';
                                                $videocount++;
                                            }
                                            $feedSection.='</div>';
                                        }
                                    }
                                   $feedSection.='<div class="listenMe"><center><img src="images/ico/13.png"></center></div>';
                                   $feedSection.='<div class="commentswhite">';
                                   $feedSection.='<div id="'.$currentPostId.'_comments" >';
                                   if(is_array($postComments) && count($postComments)>0){
                                        for($pccount=0;$pccount<count($postComments);$pccount++){
                                            $postCommentslist=$postComments[$pccount];
                                            $commentUserDetail->getUserDetails($postCommentslist["User_ID"]);
                                            $postCommentslist["Post_Comment"]=getSmileyDataForSave($postCommentslist["Post_Comment"]);
                            			$feedSection.='<!-- Comment 1 -->
                                            <div id="cmnt_row_'.$postCommentslist["User_Comment_ID"].'" class="status2">
                            				    <div class="status_top">
                            					   <div class="more_pic">
                                                       <!--
                                					   <span><img src="images/ico/13.png"></span>
                                					   <span style="margin-top:5px;">000 more...</span>
                                					   <span style="margin-top:5px; margin-left:10px;" >Pick 0</span>
                                                       -->
                                					   <div class="clearfix"></div>
                                    					<table width="100%" border="0" cellpadding="5" cellspacing="5">
                                    					   <tbody>
                                                                <tr>
                                    							     <td width="10%" rowspan="2">
                                    							         <div class="more_picture"><img src="'.$commentUserDetail->profilePicPath.'" width="40" /></div>
                                                                     </td>
                                    							     <td width="95%" class="box_home_heading" style="text-shadow:none !important">'.$postCommentslist["Full_Name"].'</td>
                                                                     <td width="5%"> <span class="removeCmnt" >X</span> </td>
                                    						     </tr>
                                    						     <tr>
                                    							     <td class="box_txt">
                                                                        <span>'.$postCommentslist["Post_Comment"].'</span>
                                                                        <span style="margin-left:20px;" >Pick <span id="cmt_'.$postCommentslist["User_Comment_ID"].'">0</span></span>
                                                                     </td>
                                                                     <td></td>
                                    						      </tr>
                                    					   </tbody>
                                                        </table>
                            					</div>
                            					<div class="clearfix"></div>
                            				</div>
                            			</div>';
                                        
                                        }
                                    }
                                    $feedSection.='</div>';
                                    if(is_array($postComments) && count($postComments)>0){
                     			        $feedSection.='
                                        <div class="com_here">
                                            <span><div class="more_picture"><img src="'.$loggedUserObjlocal->profilePicPath.'" width="40" /></div></span>
                                            <span>
                            			     <input id="'.$currentPostId.'_txtcomment" name="'.$currentPostId.'_txtcomment" type="text" class="comment" placeholder="Comment here...."  />
                                            </span>
                                            <!--
                                            <span>
                                                <input type="button" id="'.$currentPostId.'_cmdcomment" name="'.$currentPostId.'_cmdcomment" value="comment"  />
                                            </span>
                                            -->
                                        </div>';
                                    }
                                    else{
                                        $feedSection.='
                                        <div style="width: 99.5%;" class="com_here">
                                            <span><div class="more_picture"><img src="'.$loggedUserObjlocal->profilePicPath.'" width="40" /></div></span>
                                            <span>
                            			     <input id="'.$currentPostId.'_txtcomment" name="'.$currentPostId.'_txtcomment" type="text" class="comment" placeholder="Comment here...."  />
                                             </span>
                                             <!--
                                            <span>
                                                <input type="button" id="'.$currentPostId.'_cmdcomment" name="'.$currentPostId.'_cmdcomment" value="comment"  />
                                            </span>
                                            -->
                                        </div>';
                                    }
                                $feedSection.='</div>';
                                   
                $feedSection.= '</td>';
                           
                $feedSection.= '<td width="15%" valign="top" class="para">';
                                    //show like or share option only if post does not have any uploads
                                    $feedSection.=$likesharepost;
                $feedSection.= '</td>';
                          
                $feedSection.='
                          </tr>         
                    </tbody>
                </table>
                <input type="hidden" class="lstfeedtime" value="'.$newsFeeds["Post_ID"].'"/>
            </div>';
            
            return $feedSection;
            
            }
            
            
            
            
                        
           echo getNewsFeedcopy(0,$feedRecords[0],$uid);
           ?>

        </div>

		</div>
</div>
    </div>   

    <div class="clearfix"></div>

	

	

    </div>

    

    

    <div class="clearfix"></div>

    <?php include_once "common_divs_include.php"; ?>
    <div style="display: none;">
    <?php include_once "includes/footer.php"; ?>
    </div>
    

</div>

    <!--=================Footer end=======================-->

</body>

</html>